		var userID = "";
		var disc_etag = "";
		var instant_etag = "";
		var tabs = null;
		var home_tab = null;
		var browse_tab = null;
		var queues_tab = null;
		var recommendations_tab = null;
		
		var linkHistoryLength = 0;
		var linkHistory = null;
		var currentPage = null;
		
		const numberCastToDisplay = 8;
		const numberSimilarMoviesToDisplay = 8;
		
		const top_100_rss = "http://rss.netflix.com/Top100RSS";
		const new_releases_rss = "http://rss.netflix.com/NewReleasesRSS";
		const loading_main_div = "loading_main";
		
		var current_selection = null;
		var ratingImage = "";
		var notInterestedImage = "http://my-netflix.googlecode.com/svn/trunk/images/nim_low.gif";	
		
		/* -------------------------------------------------------------- */
		/* -------------------- Utility Methods ------------------------ */
		/* -------------------------------------------------------------- */
		String.prototype.trim = function() {
			return this.replace(/^\s+|\s+$/g,"");
		}

		function percentEncode(s) {
			if (s == null) {
				return "";
			}
			if (s instanceof Array) {
				var e = "";
				for (var i = 0; i < s.length; ++s) {
					if (e != "") e += '&';
					e += percentEncode(s[i]);
				}
				return e;
			}
			s = encodeURIComponent(s);
			// Now replace the values which encodeURIComponent doesn't do
			// encodeURIComponent ignores: - _ . ! ~ * ' ( )
			// OAuth dictates the only ones you can ignore are: - _ . ~
			// Source: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:encodeURIComponent
			s = s.replace("!", "%21", "g");
			s = s.replace("*", "%2A", "g");
			s = s.replace("'", "%27", "g");
			s = s.replace("(", "%28", "g");
			s = s.replace(")", "%29", "g");
			return s;
		}
		
		function goBack() {
			if (linkHistoryLength != 0) {
				var previousPage = linkHistory[linkHistoryLength - 1];
				linkHistoryLength--;
				currentPage = null;
				if (previousPage == "home") {
					getHomeScreen(true);
				} else {
					fetchData(previousPage[0], previousPage[1], previousPage[2], previousPage[3]);
				}
			}
		}
		
		function highlightNotInterested() {
			highlightStar("0");
			document.getElementById("noInterestRating").src = "http://my-netflix.googlecode.com/svn/trunk/images/nim_high.gif";
		}
		
		function highlightStar(highlightedRating) {
			document.getElementById("currentRating").src = "http://my-netflix.googlecode.com/svn/trunk/images/stars_2_" + highlightedRating + ".gif";
			document.getElementById("noInterestRating").src = "http://my-netflix.googlecode.com/svn/trunk/images/nim_low.gif";
		}
		
		function restoreStar() {
			document.getElementById("currentRating").src = ratingImage;
			document.getElementById("noInterestRating").src = notInterestedImage;
		}
		
		function submitRating(movie_id, rating, old_rating) {
			document.getElementById(loading_main_div).className = "main_loading_div_front";
			var params = {};
			var ratingLink = "";
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
			params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "netflix";
			params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
			if (old_rating == "") {
				var data = {
					title_ref : movie_id, 
					rating : rating
				};
				ratingLink = "http://api.netflix.com/users/" + userID + "/ratings/title/actual";
				params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(data);
			} else {
				var data = {
					rating : rating
				};
				var split = movie_id.split("/");
				ratingLink = "http://api.netflix.com/users/" + userID + "/ratings/title/actual/" + split[split.length -1] + "?method=PUT&rating=" + rating;
			}
			gadgets.io.makeRequest(ratingLink, function (response) {
				if (response.oauthApprovalUrl) {
					var popup = shindig.oauth.popup({
						destination: response.oauthApprovalUrl + " &application_name=iGoogle+Netflix",
						windowOptions: null,
						onOpen: null,
						onClose: function() { submitRating(movie_id, rating, old_rating); }
					});
					var personalize = document.getElementById('personalize');
					personalize.onclick = popup.createOpenerOnClick();
					var approvaldone = document.getElementById('approvaldone');
					approvaldone.onclick = popup.createApprovedOnClick();
				} else if (response.data) {
					var itemList = response.data.getElementsByTagName("status").item(0).childNodes;
					for (var i = 0; i < itemList.length ; i++) {
						if (itemList.item(i).nodeName != "#text") {
							if (itemList.item(i).nodeName == "status_code") {	
								var nodeList = itemList.item(i).childNodes;
								var code = nodeList.item(0).nodeValue;
								if (code == "200") {
									if (rating == "not_interested") {
										ratingImage = "http://my-netflix.googlecode.com/svn/trunk/images/stars_2_0.gif";
										notInterestedImage = "http://my-netflix.googlecode.com/svn/trunk/images/nim_high.gif";
									} else {
										ratingImage = "http://my-netflix.googlecode.com/svn/trunk/images/stars_2_" + rating + "0.gif";
										notInterestedImage = "http://my-netflix.googlecode.com/svn/trunk/images/nim_low.gif";
									}
									document.getElementById("noInterestRating").src = notInterestedImage;
									document.getElementById("currentRating").src = ratingImage;
								}
							}
							if (itemList.item(i).nodeName == "message") {	
								var nodeList = itemList.item(i).childNodes;
								alert(nodeList.item(0).nodeValue);
							}
						}
					}
					document.getElementById(loading_main_div).className = "main_loading_div_back";
				} else if (response.oauthError){
					alert("OAuth error: " + response.oauthError + ": " + response.oauthErrorText);
				}
			}, params);
		}
		
		function add_to_both_queues(movie_id, loading_id) {
			add_to_queue(movie_id, "disc", loading_id);
			add_to_queue(movie_id, "instant", loading_id);
		}
		
		function add_to_queue(movieID, type, loading_id) {
			document.getElementById(loading_id).className = "queue_loading_div_front";
			updateQueue(movieID, null, type, loading_id);
		}
		
	    // Process returned JSON feed to display data.
		function showResults(result, type, loading_id, queue) {			
			if (type == "actors") {
				showActors(result);
			} else if (type == "actor_details") {
				showActorDetails(result);
			} else if (type == "queue") {
				showQueue(result, queue, loading_id);
			} else if (type == "movies") {
				showMovies(result);
			} else if (type == "movie_details") {
				showMovieDetails(result);
			} else if (type == "at_home") {
				showAtHomeFeed(result);
			} else if (type == "returned") {
				showReturned(result);
			}
		}
		
	    function fetchData(url, type, loading_id, queue) {
			if (type != "queue" && type != "at_home" && type != "returned") {
				document.getElementById(loading_main_div).className = "main_loading_div_front";
				if (currentPage != null) {
					linkHistory[linkHistoryLength] = currentPage;
					linkHistoryLength++;
				}
				currentPage = new Array();
				currentPage[0] = url;
				currentPage[1] = type;
				currentPage[2] = loading_id;
				currentPage[3] = queue;
			}
			if (linkHistoryLength > 0) {
				document.getElementById("back_link").style.display = "inline";
			} else {
				document.getElementById("back_link").style.display = "none";
			}
			
			var params = {};
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
			params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "netflix";
			params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
			gadgets.io.makeRequest(url, function (response) {
				if (response.oauthApprovalUrl) {
					var popup = shindig.oauth.popup({
						destination: response.oauthApprovalUrl + "&application_name=iGoogle+Netflix",
						windowOptions: null,
						onOpen: null,
						onClose: function() { fetchData(url, type, loading_id, queue); }
					});
					var personalize = document.getElementById('personalize');
					personalize.onclick = popup.createOpenerOnClick();
					var approvaldone = document.getElementById('approvaldone');
					approvaldone.onclick = popup.createApprovedOnClick();
				} else if (response.data) {
					showResults(response.data, type, loading_id, queue);
				} else {
					// The response.oauthError and response.oauthErrorText values may help debug
					// problems with your gadget.
					alert("OAuth error: " + response.oauthError + ": " + response.oauthErrorText);
				}
			}, params);
	    }
			
		function updateEtag(response, queue, loading_id) {
			var itemList = response.getElementsByTagName("status").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "etag") {
						if (queue == "disc") {
							disc_etag = itemList.item(i).firstChild.nodeValue;
						} else if (queue == "instant") {
							instant_etag = itemList.item(i).firstChild.nodeValue;
						}
					}
				}
			}
			if (loading_id != null) {
				document.getElementById(loading_id).className = "queue_loading_div_back";
				updateQueueSelected();
			}
		}
		
		function postData(url, postdata, queue, loading_id) {
			var params = {};
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
			params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "netflix";
			params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
			params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
			gadgets.io.makeRequest(url, function (response) {
				if (response.oauthApprovalUrl) {
					var popup = shindig.oauth.popup({
						destination: response.oauthApprovalUrl + "&application_name=iGoogle+Netflix",
						windowOptions: null,
						onOpen: null ,
						onClose: function() { fetchData(url, type, loading_id, queue); }
					});
					
					var personalize = document.getElementById('personalize');
					personalize.onclick = popup.createOpenerOnClick();
					var approvaldone = document.getElementById('approvaldone');
					approvaldone.onclick = popup.createApprovedOnClick();
				} else if (response.data) {
					updateEtag(response.data, queue, loading_id);
				} else {
					// The response.oauthError and response.oauthErrorText values may help debug
					// problems with your gadget.
					alert("OAuth error: " + response.oauthError + ": " + response.oauthErrorText);
				}
			}, params);
		}
		
		function getUserID() {
			var params = {};
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
			params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "netflix";
			params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
			gadgets.io.makeRequest("http://api.netflix.com/users/current", function (response) {
				if (response.oauthApprovalUrl) {
					// user has not allowed access to Netflix
				} else if (response.data) {
					// get and store user id
					var itemList = response.data.getElementsByTagName("resource").item(0).childNodes;
					for (var i = 0; i < itemList.length ; i++) {
						if (itemList.item(i).nodeName != "#text") {
							if (itemList.item(i).nodeName == "link") {
								if (itemList.item(i).attributes.item(2).value == "current user") {
									var temp_url = itemList.item(i).attributes.item(0).value;
									var temp_user_id = temp_url.split("/");
									userID = temp_user_id[temp_user_id.length-1];
									
									fetchData("http://api.netflix.com/users/" + userID + "/at_home?max_results=5", "at_home");
									fetchData("http://api.netflix.com/users/" + userID + "/rental_history/returned?max_results=5", "returned");
									updateQueueSelected();
								}
							}
						}
					}
				} else {
					// The response.oauthError and response.oauthErrorText values may help debug
					// problems with your gadget.
					alert("OAuth error: " + response.oauthError + ": " + response.oauthErrorText);
				}
			}, params);
		}

		function selectSubTabs(id, tab) {
			var subTabs;
			if (tab == "browse") {
				subTabs = browse_sub_tabs;
			} else if (tab == "queue") {
				subTabs = queues_sub_tabs;
			}
			var el = _gel(id);
			if (el.className.indexOf("subTab_unselected__MODULE_ID__") != -1) {
				for (var i = 0; i < subTabs.length; i++) {
					var subTab = document.getElementById(subTabs[i]);
					if (id == subTabs[i]) {
						subTab.className = "subTab_selected__MODULE_ID__";
					} else {
						subTab.className = "subTab_unselected__MODULE_ID__";
					}
				}
			}	
		}
		
		function clearArea(object) {
			while (document.getElementById(object).hasChildNodes()) {
				document.getElementById(object).removeChild(document.getElementById(object).firstChild);
			}
		}
		
		/* -------------------------------------------------------------- */
		/* -------------------- Search Methods ----------------------- */
		/* -------------------------------------------------------------- */
		function search() {
			if (document.getElementById("search").value.trim() != "") {
				var type = document.getElementById("searchType").value;
				document.getElementById(loading_main_div).className = "main_loading_div_front";
				if (type == "movie") {
					fetchData("http://api.netflix.com/catalog/titles?expand=formats&term=" +  percentEncode(document.getElementById("search").value.trim()), "movies", "browse_tab_loading");
				} else if (type == "actor") {
					fetchData("http://api.netflix.com/catalog/people?expand=filmography&term=" +  percentEncode(document.getElementById("search").value.trim()), "actors", "browse_tab_loading");
				}
			}		
		}
	
		function catchEnter(event) {
			var key = event.keyCode || event.which;
			if (key == 13){
				search();
			}
		}
		
		function showMovieDetails(response) {
			clearArea("result_output");
			
			var instantAvailable = false;
			var bluRayAvailable = false;
			var dvdAvailable = false;
			var movie_id = "";
			var ratings_id = "";
			var box_art = "";
			var name = "";
			var year = "";
			var runtime = 0;
			var synopsis = "";
			var director_list = new Array();
			var aveRating = "";
			var myRating = "";
			var cast_list = new Array();
			var similar_movies_list = new Array();
			var results_area = document.getElementById("result_output");
			var itemList = response.getElementsByTagName("ratings").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "ratings_item") {	
						var nodeList = itemList.item(i).childNodes;
						for (var j = 0; j < nodeList.length ; j++) {
							var node = nodeList.item(j);
							if (node.nodeName == "id") {
								ratings_id = node.firstChild.nodeValue;
							}
							if (node.nodeName == "link" && node.attributes.item(1).value == "http://schemas.netflix.com/catalog/title") {
								movie_id = node.attributes.item(0).value;
							}							
							if (node.nodeName == "box_art") {
								box_art = node.attributes.item(2).value;
							}
							if (node.nodeName == "title") {
								name = node.attributes.item("regular").value;
							}
							if (node.nodeName == "release_year") {
								year = node.firstChild.nodeValue;
							}
							if (node.nodeName == "runtime") {
								runtime = node.firstChild.nodeValue;
							}
							if (node.nodeName == "category" && node.attributes.item(0).value == "http://api.netflix.com/categories/mpaa_ratings") {
								movieRating = node.attributes.item(2).value;
							}
							if (node.nodeName == "average_rating") {
								aveRating = node.firstChild.nodeValue;
							}
							if (node.nodeName == "user_rating") { 
								if (node.firstChild == null) { 
									myRating = node.attributes.item(0).nodeValue; 
								} else { 
									myRating = node.firstChild.nodeValue; 
								} 
							}
							if (node.nodeName == "link" && node.attributes.item(2).value == "synopsis") {
								synopsis = node.firstChild.firstChild.nodeValue;
							}
							if (node.nodeName == "link" && node.attributes.item(2).value == "formats") {
								var formats = node.firstChild.childNodes;
								for (var k = 0; k < formats.length; k++) {	
									if (formats.item(k).firstChild.attributes.item(2).value == "DVD") {
										dvdAvailable = true;
									}								
									if (formats.item(k).firstChild.attributes.item(2).value == "instant") {
										instantAvailable = true;
									}
									if (formats.item(k).firstChild.attributes.item(2).value == "Blu-ray") {
										bluRayAvailable = true;
									}
								}
							}
							if (node.nodeName == "link" && node.attributes.item(2).value == "directors") {
								if (node.firstChild != null) {
									var movie_directors = node.firstChild.childNodes;
									for (var k = 0; k < movie_directors.length; k++) {
										var person = document.createElement("a");
										person.setAttribute("style", "cursor:pointer;cursor:hand;");
										person.setAttribute("onClick", "fetchData('" + movie_directors[k].attributes.item(0).value + "?expand=filmography', 'actor_details');");
										person.appendChild(document.createTextNode(movie_directors[k].attributes.item(2).value));
										director_list[k] = person;
									}
								}
							}
							if (node.nodeName == "link" && node.attributes.item(2).value == "cast") {
								if (node.firstChild != null) {
									var movie_cast = node.firstChild.childNodes;
									var movie_cast_length;
									if (movie_cast.length > numberCastToDisplay) {
										movie_cast_length = 8;
									} else {
										movie_cast_length = movie_cast.length;
									}
									for (var k = 0; k < movie_cast_length; k++) {
										var movie_actor = document.createElement("a");
										movie_actor.setAttribute("style", "cursor:pointer;cursor:hand;");
										movie_actor.setAttribute("onClick", "fetchData('" + movie_cast[k].attributes.item(0).value + "?expand=filmography', 'actor_details');");
										movie_actor.appendChild(document.createTextNode(movie_cast[k].attributes.item(2).value));
										cast_list[k] = movie_actor;
									}
								}
							}
							if (node.nodeName == "link" && node.attributes.item(2).value == "similars") {
								if (node.firstChild != null) {
									var similar_movies = node.firstChild.childNodes;
									var similar_movies_length;
									if (similar_movies.length > numberSimilarMoviesToDisplay) {
										similar_movies_length = 8;
									} else {
										similar_movies_length = similar_movies.length;
									}
									for (var k = 0; k < similar_movies_length; k++) {
										var similar_movie_title = document.createElement("a");
										similar_movie_title.setAttribute("style", "cursor:pointer;cursor:hand;");
										similar_movie_title.setAttribute("onClick", "fetchData('http://api.netflix.com/users/" + userID + "/ratings/title?title_refs=" + percentEncode(similar_movies[k].attributes.item(0).value) + "&expand=cast,directors,formats,similars,synopsis', 'movie_details', '" + loading_main_div + "');");
										similar_movie_title.appendChild(document.createTextNode(similar_movies[k].attributes.item(2).value));
										similar_movies_list[k] = similar_movie_title;
									}
								}
							}
						}
					}
				}
			}
			var result_table = document.createElement("table");
			results_area.appendChild(result_table);
			var first_row = document.createElement("tr");
			result_table.appendChild(first_row);
			var box_art_cell = document.createElement("td");
			first_row.appendChild(box_art_cell);
			box_art_cell.setAttribute("style", "padding-right: 10px; padding-bottom: 10px;");
			
			var box_art_image = document.createElement("img");
			box_art_image.setAttribute("src", box_art);
			box_art_image.setAttribute("alt", name);
			box_art_cell.appendChild(box_art_image);
			
			var movie_metadata_cell = document.createElement("td");
			first_row.appendChild(movie_metadata_cell);
			movie_metadata_cell.setAttribute("align", "right");
			movie_metadata_cell.setAttribute("style", "vertical-align:top;width:100%;");
			
			var titleHeader = document.createElement("div");
			movie_metadata_cell.appendChild(titleHeader);
			titleHeader.setAttribute("style", "text-align:left;");
			var movie_title = document.createElement("span");
			movie_title.className = "header";
			movie_title.appendChild(document.createTextNode(name + " "));
			titleHeader.appendChild(movie_title);
			
			var movie_year = document.createElement("span");
			movie_year.setAttribute("style", "font-size:small;");
			movie_year.appendChild(document.createTextNode( "(" + year + ")"));
			titleHeader.appendChild(movie_year);
			
			titleHeader.appendChild(document.createTextNode(" - " + movieRating));
			titleHeader.appendChild(document.createElement("br"));
			
			if (myRating != "") {
				if (myRating != "not_interested") {
					ratingImage = "http://my-netflix.googlecode.com/svn/trunk/images/stars_2_" + myRating.replace(".", "") + ".gif";
				} else {
					ratingImage = "http://my-netflix.googlecode.com/svn/trunk/images/stars_2_0.gif";
					notInterestedImage = "http://my-netflix.googlecode.com/svn/trunk/images/nim_high.gif";
				}
			} else {
				ratingImage = "http://my-netflix.googlecode.com/svn/trunk/images/stars_1_" + aveRating.replace(".", "") + ".gif";
			}
			var aveRatingCell = document.createElement("div");
			titleHeader.appendChild(aveRatingCell);
			aveRatingCell.className = "text";
			var noInterestImg = document.createElement("img");
			noInterestImg.setAttribute("id", "noInterestRating");
			noInterestImg.setAttribute("src", notInterestedImage);
			noInterestImg.setAttribute("alt", "Not Interested");
			noInterestImg.setAttribute("onmouseover", "highlightNotInterested();");
			noInterestImg.setAttribute("onmouseout", "restoreStar();");
			noInterestImg.setAttribute("onclick", "submitRating('" + movie_id + "', 'not_interested', '" + myRating + "');");
			noInterestImg.setAttribute("style", "cursor:pointer;cursor:hand;");
			aveRatingCell.appendChild(noInterestImg);
			var aveRatingImg = document.createElement("img");
			aveRatingImg.setAttribute("id", "currentRating");
			aveRatingImg.setAttribute("src", ratingImage);
			aveRatingImg.setAttribute("alt", aveRating);
			aveRatingImg.setAttribute("style", "border-style: none;");
			aveRatingImg.setAttribute("usemap", "#ratings");
			aveRatingCell.appendChild(aveRatingImg);
			
			var ratingsMap = document.createElement("map");
			titleHeader.appendChild(ratingsMap);
			ratingsMap.setAttribute("name", "ratings");
			var oneStarArea = document.createElement("area");
			ratingsMap.appendChild(oneStarArea);
			oneStarArea.setAttribute("shape", "rect");
			oneStarArea.setAttribute("alt", "1-Star");
			oneStarArea.setAttribute("coords", "0, 0, 18, 15");
			oneStarArea.setAttribute("onmouseover", "highlightStar(10);");
			oneStarArea.setAttribute("onmouseout", "restoreStar();");
			oneStarArea.setAttribute("onclick", "submitRating('" + movie_id + "', '1', '" + myRating + "');");
			oneStarArea.setAttribute("style", "cursor:pointer;cursor:hand;");
			
			var twoStarArea = document.createElement("area");
			ratingsMap.appendChild(twoStarArea);
			twoStarArea.setAttribute("shape", "rect");
			twoStarArea.setAttribute("alt", "2-Star");
			twoStarArea.setAttribute("coords", "18, 0, 37, 15");
			twoStarArea.setAttribute("onmouseover", "highlightStar(20);");
			twoStarArea.setAttribute("onmouseout", "restoreStar();");
			twoStarArea.setAttribute("onclick", "submitRating('" + movie_id + "', '2', '" + myRating + "');");
			twoStarArea.setAttribute("style", "cursor:pointer;cursor:hand;");
			
			var threeStarArea = document.createElement("area");
			ratingsMap.appendChild(threeStarArea);
			threeStarArea.setAttribute("shape", "rect");
			threeStarArea.setAttribute("alt", "3-Star");
			threeStarArea.setAttribute("coords", "37, 0, 54, 15");
			threeStarArea.setAttribute("onmouseover", "highlightStar(30);");
			threeStarArea.setAttribute("onmouseout", "restoreStar();");
			threeStarArea.setAttribute("onclick", "submitRating('" + movie_id + "', '3', '" + myRating + "');");
			threeStarArea.setAttribute("style", "cursor:pointer;cursor:hand;");
			
			var fourStarArea = document.createElement("area");
			ratingsMap.appendChild(fourStarArea);
			fourStarArea.setAttribute("shape", "rect");
			fourStarArea.setAttribute("alt", "4-Star");
			fourStarArea.setAttribute("coords", "54, 0, 73, 15");
			fourStarArea.setAttribute("onmouseover", "highlightStar(40);");
			fourStarArea.setAttribute("onmouseout", "restoreStar();");
			fourStarArea.setAttribute("onclick", "submitRating('" + movie_id + "', '4', '" + myRating + "');");
			fourStarArea.setAttribute("style", "cursor:pointer;cursor:hand;");
			
			var fiveStarArea = document.createElement("area");
			ratingsMap.appendChild(fiveStarArea);
			fiveStarArea.setAttribute("shape", "rect");
			fiveStarArea.setAttribute("alt", "5-Star");
			fiveStarArea.setAttribute("coords", "73, 0, 91, 15");
			fiveStarArea.setAttribute("onmouseover", "highlightStar(50);");
			fiveStarArea.setAttribute("onmouseout", "restoreStar();");
			fiveStarArea.setAttribute("onclick", "submitRating('" + movie_id + "', '5', '" + myRating + "');");
			fiveStarArea.setAttribute("style", "cursor:pointer;cursor:hand;");
			
			titleHeader.appendChild(document.createElement("br"));
			
			var formatsCell = document.createElement("div");
			formatsCell.className = "text";
			formatsCell.appendChild(document.createTextNode("Formats Available: "));
			if (dvdAvailable) {
				var dvdIcon = document.createElement("img");
				dvdIcon.setAttribute("src", "http://my-netflix.googlecode.com/svn/trunk/images/DVD-16x16.png");
				dvdIcon.setAttribute("alt", "DVD");
				dvdIcon.setAttribute("style", "padding-right:5px;");
				formatsCell.appendChild(dvdIcon);
			} 
			if (bluRayAvailable) {
				var bluRayIcon = document.createElement("img");
				bluRayIcon.setAttribute("src", "http://my-netflix.googlecode.com/svn/trunk/images/blu-ray-16x16.png");
				bluRayIcon.setAttribute("alt", "Blu-ray");
				bluRayIcon.setAttribute("style", "padding-right:5px;");
				formatsCell.appendChild(bluRayIcon);
			}
			if (instantAvailable) {
				var instantIcon = document.createElement("img");
				instantIcon.setAttribute("src", "http://my-netflix.googlecode.com/svn/trunk/images/Button-Play-16x16.png");
				instantIcon.setAttribute("alt", "Instant Play");
				instantIcon.setAttribute("style", "padding-right:5px;");
				formatsCell.appendChild(instantIcon);
			} 
			titleHeader.appendChild(formatsCell);
			
			var directorsDiv = document.createElement("div");
			directorsDiv.className = "text";
			directorsDiv.appendChild(document.createTextNode("Director: "));
			for (var i = 0; i < director_list.length; i++) {
				if (i != 0) {
					directorsDiv.appendChild(document.createTextNode(", "));
				}
				directorsDiv.appendChild(director_list[i]);
			}
			titleHeader.appendChild(directorsDiv);
			
			var runtimeDiv = document.createElement("div");
			runtimeDiv.className = "text";
			runtimeDiv.appendChild(document.createTextNode("Runtime: " + runtime/60 + " minutes"));
			titleHeader.appendChild(runtimeDiv);
			
			var addToQueueDiv = document.createElement("div");
			titleHeader.appendChild(addToQueueDiv);
			addToQueueDiv.className = "text";
			addToQueueDiv.appendChild(document.createTextNode("Add To Queue: "));
			var disc_link = document.createElement("a");
			disc_link.setAttribute("style", "cursor:pointer;cursor:hand;");
			disc_link.setAttribute("onClick", "add_to_queue('" + movie_id + "', 'disc', 'queue_tab_loading');");
			disc_link.appendChild(document.createTextNode("Disc"));
			addToQueueDiv.appendChild(disc_link);
			
			if (instantAvailable) {
				addToQueueDiv.appendChild(document.createTextNode(" | "));
				var instant_link = document.createElement("a");
				instant_link.setAttribute("style", "cursor:pointer;cursor:hand;");
				instant_link.setAttribute("onClick", "add_to_queue('" + movie_id + "', 'instant', 'queue_tab_loading');");
				instant_link.appendChild(document.createTextNode("Instant"));
				addToQueueDiv.appendChild(instant_link);
				
				addToQueueDiv.appendChild(document.createTextNode(" | "));
				var both_link = document.createElement("a");
				both_link.setAttribute("style", "cursor:pointer;cursor:hand;");
				both_link.setAttribute("onClick", "add_to_both_queues('" + movie_id + "', 'queue_tab_loading');");
				both_link.appendChild(document.createTextNode("Both"));
				addToQueueDiv.appendChild(both_link);
			
				var ratingID = movie_id.split("/");
				var watchNowDiv = document.createElement("div");
				watchNowDiv.className = "text";
				var watch_now_link = document.createElement("a");
				watch_now_link.setAttribute("style", "cursor:pointer;cursor:hand;");
				watch_now_link.setAttribute("onClick", "window.open('http://www.netflix.com/WiPlayer?movieid=" + ratingID[ratingID.length - 1] + "')");
				watch_now_link.appendChild(document.createTextNode("Watch Now"));
				watchNowDiv.appendChild(watch_now_link);
				titleHeader.appendChild(watchNowDiv);
			}
			
			var synopsis_row = document.createElement("tr");
			result_table.appendChild(synopsis_row);
			var synopsis_cell = document.createElement("td");
			synopsis_row.appendChild(synopsis_cell);
			synopsis_cell.setAttribute("colspan", "2");
			synopsis_cell.className = "section";
			
			var synopsis_header = document.createElement("div");
			synopsis_cell.appendChild(synopsis_header);
			synopsis_header.className = "sectionHeader";
			synopsis_header.appendChild(document.createTextNode("Synopsis:"));
			
			var synopsis_body = document.createElement("div");
			synopsis_cell.appendChild(synopsis_body);
			synopsis_body.className = "sectionText";
			var split = synopsis.split(/<a href=\"/);
			for (var i = 0; i < split.length; i++) {
				var split2 = split[i].split(/<\/a>/);
				for (var j=0; j < split2.length; j++) {
					if (i != 0 && j == 0) {
						var link_parts = split2[j].split(/\">/);
						var url_parts = link_parts[0].split(/\//);
						var synopsis_link = document.createElement("a");
						synopsis_link.setAttribute("style", "cursor:pointer;cursor:hand;");
						synopsis_link.setAttribute("onClick", "fetchData('http://api.netflix.com/catalog/people/" + url_parts[url_parts.length-1] + "?expand=filmography', 'actor_details');");
						synopsis_link.innerHTML = synopsis_link.innerHTML + link_parts[1];
						synopsis_body.appendChild(synopsis_link);
					} else {
						synopsis_body.innerHTML = synopsis_body.innerHTML + split2[j];
					}
				}
			}
			
			var cast_row = document.createElement("tr");
			result_table.appendChild(cast_row);
			var cast_cell = document.createElement("td");
			cast_row.appendChild(cast_cell);
			cast_cell.setAttribute("colspan", "2");
			cast_cell.className = "section";
			
			var cast_header = document.createElement("div");
			cast_cell.appendChild(cast_header);
			cast_header.className = "sectionHeader";
			cast_header.appendChild(document.createTextNode("Cast:"));
			
			var cast_body = document.createElement("div");
			cast_cell.appendChild(cast_body);
			cast_body.className = "sectionText";
			
			var castTable = document.createElement("table");
			cast_body.appendChild(castTable);
			var castRow = document.createElement("tr");
			for (var i = 0; i < cast_list.length; i++) {
				if (i % 2 == 0 && i != 0) {
					castTable.appendChild(castRow);
					castRow = document.createElement("tr");
				} else if (i == cast_list.length - 1) {
					castTable.appendChild(castRow);
				}
				var castCell = document.createElement("td");
				castCell.setAttribute("style", "padding-right:20px;");
				castCell.appendChild(cast_list[i]);
				castRow.appendChild(castCell);
			}
			
			var similar_movies_row = document.createElement("tr");
			result_table.appendChild(similar_movies_row);
			var similar_movies_cell = document.createElement("td");
			similar_movies_row.appendChild(similar_movies_cell);
			similar_movies_cell.setAttribute("colspan", "2");
			similar_movies_cell.className = "section";
			
			var similar_movies_header = document.createElement("div");
			similar_movies_cell.appendChild(similar_movies_header);
			similar_movies_header.className = "sectionHeader";
			similar_movies_header.appendChild(document.createTextNode("Similar Movies:"));
			
			var similar_movies_body = document.createElement("div");
			similar_movies_cell.appendChild(similar_movies_body);
			similar_movies_body.className = "sectionText";
			
			var similarMoviesTable = document.createElement("table");
			similar_movies_body.appendChild(similarMoviesTable);
			var similarMoviesRow = document.createElement("tr");
			for (var i = 0; i < similar_movies_list.length; i++) {
				if (i % 2 == 0 && i != 0) {
					similarMoviesTable.appendChild(similarMoviesRow);
					similarMoviesRow = document.createElement("tr");
				} else if (i == similar_movies_list.length - 1) {
					similarMoviesTable.appendChild(similarMoviesRow);
				}
				var similarMoviesCell = document.createElement("td");
				similarMoviesCell.setAttribute("style", "padding-right:20px;");
				similarMoviesCell.appendChild(similar_movies_list[i]);
				similarMoviesRow.appendChild(similarMoviesCell);
			}
			
			document.getElementById(loading_main_div).className = "main_loading_div_back";
		}
		
		function showMovies(response) {
			clearArea("result_output");

			var catalogTable = document.createElement("table");
			catalogTable.setAttribute("width", "100%");
			catalogTable.setAttribute("cellspacing", "0");
			catalogTable.setAttribute("cellpadding", "1");
			var headerRow = document.createElement("tr");
			headerRow.className = "table_header";
			
			var titleColumn = document.createElement("td");
			titleColumn.appendChild(document.createTextNode("Movie Title"));
			var aveRatingColumn = document.createElement("td");
			aveRatingColumn.appendChild(document.createTextNode("Average Rating"));
			var formatsColumn = document.createElement("td");
			formatsColumn.appendChild(document.createTextNode("Available Formats"));
			var addToQueueColumn = document.createElement("td");
			addToQueueColumn.appendChild(document.createTextNode("Add to Queue"));
			
			headerRow.appendChild(titleColumn);
			headerRow.appendChild(aveRatingColumn);
			headerRow.appendChild(formatsColumn);
			headerRow.appendChild(addToQueueColumn);
			catalogTable.appendChild(headerRow);
			
			var results_area = document.getElementById("result_output");
			var itemList = response.getElementsByTagName("catalog_titles").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {	
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "catalog_title") {	
						var instantAvailable = false;
						var bluRayAvailable = false;
						var movie_id = "";
						var name = "";
						var year = "";
						var aveRating = "";
						var nodeList = itemList.item(i).childNodes;
						for (var j = 0; j < nodeList.length ; j++) {
							var node = nodeList.item(j);
							if (node.nodeName != "#text") {
								if (node.nodeName == "id") {
									movie_id = node.firstChild.nodeValue;
								}
								if (node.nodeName == "title") {
									name = node.attributes.item("regular").value;
								}
								if (node.nodeName == "release_year") {
									year = node.firstChild.nodeValue;
								}
								if (node.nodeName == "category" && node.attributes.item(0).value == "http://api.netflix.com/categories/mpaa_ratings") {
									movieRating = node.attributes.item(2).value;
								}
								if (node.nodeName == "average_rating") {
									aveRating = node.firstChild.nodeValue;
								}
								if (node.nodeName == "link" && node.attributes.item(2).value == "formats") {
									var formats = node.firstChild.childNodes;
									for (var k = 0; k < formats.length; k++) {
										if (formats.item(k).firstChild.attributes.item(2).value == "instant") {
											instantAvailable = true;
										}
										if (formats.item(k).firstChild.attributes.item(2).value == "Blu-ray") {
											bluRayAvailable = true;
										}
									}
								}
							}
						}
						var resultRow = document.createElement("tr");
						var movieTitle = document.createElement("td");
						var movie_link = document.createElement("a");
						movie_link.setAttribute("style", "cursor:pointer;cursor:hand;");
						movie_link.setAttribute("onClick", "fetchData('http://api.netflix.com/users/" + userID + "/ratings/title?title_refs=" + percentEncode(movie_id) + "&expand=cast,directors,formats,similars,synopsis', 'movie_details', '" + loading_main_div + "');");
						movie_link.appendChild(document.createTextNode(name + "(" + year + ")" + "-" + movieRating));
						movieTitle.appendChild(movie_link);
						
						var aveRatingCell = document.createElement("td");
						aveRatingCell.setAttribute("align", "center");
						aveRatingCell.appendChild(document.createTextNode(aveRating));

						var formatsCell = document.createElement("td");
						formatsCell.setAttribute("align", "center");
						if (bluRayAvailable) {
							var bluRayIcon = document.createElement("img");
							bluRayIcon.setAttribute("src", "http://my-netflix.googlecode.com/svn/trunk/images/blu-ray-16x16.png");
							bluRayIcon.setAttribute("alt", "Blu-ray");
							bluRayIcon.setAttribute("style", "padding-right:5px;");
							formatsCell.appendChild(bluRayIcon);
						}
						if (instantAvailable) {
							var instantIcon = document.createElement("img");
							instantIcon.setAttribute("src", "http://my-netflix.googlecode.com/svn/trunk/images/Button-Play-16x16.png");
							instantIcon.setAttribute("alt", "Instant Play");
							instantIcon.setAttribute("style", "padding-right:5px;");
							formatsCell.appendChild(instantIcon);
						} 
						
						var addToQueue = document.createElement("td");	
						addToQueue.setAttribute("align", "center");
						var link = document.createElement("a");
						link.setAttribute("style", "cursor:pointer;cursor:hand;");
						if (instantAvailable) {
							link.setAttribute("onClick", "add_to_both_queues('" + movie_id + "', 'queue_tab_loading');");
						} else {
							link.setAttribute("onClick", "add_to_queue('" + movie_id + "', 'disc', 'queue_tab_loading');");
						}
						link.appendChild(document.createTextNode("+"));
						addToQueue.appendChild(link);
						
						resultRow.appendChild(movieTitle);
						resultRow.appendChild(aveRatingCell);
						resultRow.appendChild(formatsCell);
						resultRow.appendChild(addToQueue);
						catalogTable.appendChild(resultRow);
					}
				}
			}
			results_area.appendChild(catalogTable);
			
			document.getElementById(loading_main_div).className = "main_loading_div_back";
		}
		
		function showActorDetails(response) {
			clearArea("result_output");
			
			var name = "";
			var bio = "";
			var films_list = new Array();
			var results_area = document.getElementById("result_output");
			var itemList = response.getElementsByTagName("person").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {	
				var node = itemList.item(i);
				if (node.nodeName != "#text") {
					if (node.nodeName == "name") {
						name = node.firstChild.nodeValue;
					}
					if (node.nodeName == "bio") {
						bio = node.firstChild.nodeValue;
					}
					if (node.nodeName == "link" && node.attributes.item(2).value == "filmography") {
						var movies_made = node.firstChild.childNodes;
						for (var k = 0; k < movies_made.length; k++) {
							var movie_made = document.createElement("a");
							movie_made.setAttribute("style", "cursor:pointer;cursor:hand;");
							movie_made.setAttribute("onClick", "fetchData('http://api.netflix.com/users/" + userID + "/ratings/title?title_refs=" + percentEncode(movies_made[k].attributes.item(0).value) + "&expand=cast,directors,formats,similars,synopsis', 'movie_details', '" + loading_main_div + "');");
							movie_made.appendChild(document.createTextNode(movies_made[k].attributes.item(2).value));
							films_list[k] = movie_made;
						}
					}
				}
			}
			var result_table = document.createElement("table");
			results_area.appendChild(result_table);
			var first_row = document.createElement("tr");
			result_table.appendChild(first_row);
			
			var actor_name_cell = document.createElement("td");
			first_row.appendChild(actor_name_cell);
			actor_name_cell.setAttribute("style", "vertical-align:top;width:100%;");
			
			var titleHeader = document.createElement("div");
			actor_name_cell.appendChild(titleHeader);
			titleHeader.setAttribute("style", "text-align:left;");
			var actor_name = document.createElement("span");
			actor_name.className = "header";
			actor_name.appendChild(document.createTextNode(name));
			titleHeader.appendChild(actor_name);
			
			var bio_row = document.createElement("tr");
			result_table.appendChild(bio_row);
			var bio_cell = document.createElement("td");
			bio_row.appendChild(bio_cell);
			bio_cell.className = "section";
			
			var bio_header = document.createElement("div");
			bio_cell.appendChild(bio_header);
			bio_header.className = "sectionHeader";
			bio_header.appendChild(document.createTextNode("Bio:"));
			
			var bio_body = document.createElement("div");
			bio_body.className = "sectionText";
			bio_body.innerHTML = bio;
			bio_cell.appendChild(bio_body);
			
			var similar_movies_row = document.createElement("tr");
			result_table.appendChild(similar_movies_row);
			var similar_movies_cell = document.createElement("td");
			similar_movies_row.appendChild(similar_movies_cell);
			similar_movies_cell.className = "section";
			
			var similar_movies_header = document.createElement("div");
			similar_movies_cell.appendChild(similar_movies_header);
			similar_movies_header.className = "sectionHeader";
			similar_movies_header.appendChild(document.createTextNode("Filmography:"));
			
			var similar_movies_body = document.createElement("div");
			similar_movies_cell.appendChild(similar_movies_body);
			similar_movies_body.className = "sectionText";
			
			var moviesTable = document.createElement("table");
			similar_movies_body.appendChild(moviesTable);
			var moviesRow = document.createElement("tr");
			for (var i = 0; i < films_list.length; i++) {
				if (i % 2 == 0 && i != 0) {
					moviesTable.appendChild(moviesRow);
					moviesRow= document.createElement("tr");
				} else if (i == films_list.length - 1) {
					moviesTable.appendChild(moviesRow);
				}
				var movieCell = document.createElement("td");
				movieCell.setAttribute("style", "padding-right:20px;");
				movieCell.appendChild(films_list[i]);
				moviesRow.appendChild(movieCell);
			}
			
			document.getElementById(loading_main_div).className = "main_loading_div_back";
		}
		
		function showActors(response) {
			clearArea("result_output");

			var catalogTable = document.createElement("table");
			catalogTable.setAttribute("width", "100%");
			catalogTable.setAttribute("cellspacing", "0");
			catalogTable.setAttribute("cellpadding", "1");
			var headerRow = document.createElement("tr");
			headerRow.className = "table_header";
			
			var actorColumn = document.createElement("td");
			actorColumn.appendChild(document.createTextNode("Actor"));
			
			headerRow.appendChild(actorColumn);
			catalogTable.appendChild(headerRow);
			
			var results_area = document.getElementById("result_output");
			var itemList = response.getElementsByTagName("people").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {	
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "person") {
						var actorName = "";
						var actor_id = "";
						var nodeList = itemList.item(i).childNodes;
						for (var j = 0; j < nodeList.length ; j++) {
							var node = nodeList.item(j);
							if (node.nodeName != "#text") {
								if (node.nodeName == "id") {
									actor_id = node.firstChild.nodeValue;
								}
								if (node.nodeName == "name") {
									actorName = node.firstChild.nodeValue;
								}
							}
						}
						var resultRow = document.createElement("tr");
						var actorCell = document.createElement("td");
						var actor_link = document.createElement("a");
						actor_link.setAttribute("style", "cursor:pointer;cursor:hand;");
						actor_link.setAttribute("onClick", "fetchData('" + actor_id + "?expand=filmography', 'actor_details');");
						actor_link.appendChild(document.createTextNode(actorName));
						actorCell.appendChild(actor_link);
						
						resultRow.appendChild(actorCell);
						catalogTable.appendChild(resultRow);
					}
				}
			}
			results_area.appendChild(catalogTable);
			document.getElementById(loading_main_div).className = "main_loading_div_back";
		}
		
		/* -------------------------------------------------------------- */
		/* --------------------- Queue Methods -------------------------- */
		/* -------------------------------------------------------------- */
		queues_sub_tabs = ["disc__MODULE_ID__", "instant__MODULE_ID__"];
		function get_queue(type) {
			document.getElementById("queue_tab_loading").className = "queue_loading_div_front";
			if (type == "disc") {
				fetchData("http://api.netflix.com/users/" + userID + "/queues/disc?max_results=500", "queue", "queue_tab_loading", "disc");
			} else if(type == "instant") {
				fetchData("http://api.netflix.com/users/" + userID + "/queues/instant?max_results=500", "queue", "queue_tab_loading", "instant");
			}
		}

		function queueToShow(id, type) {
			document.getElementById("q_results").className = "hide";
			selectSubTabs(id, "queue");
			
			get_queue(type);
			document.getElementById("q_results").className = "queue_results";
		}

		function updateQueueSelected() {
			var queueSelected = -1;
			var i;
			for (i = 0; i < queues_sub_tabs.length; i++) {
				var queueTab = document.getElementById(queues_sub_tabs[i]).className;
				if (queueTab != "subTab_unselected__MODULE_ID__") {
					queueSelected = i;
				}
			}
			if (queueSelected == -1) {
				queueToShow(queues_sub_tabs[0], "disc");
			} else {
				if (queueSelected == 0) {
					queueToShow(queues_sub_tabs[queueSelected], "disc");
				} else if (queueSelected == 1) {
					queueToShow(queues_sub_tabs[queueSelected], "instant");
				}
			}
		}

		function updateQueue(movieID, position, type, loading_id) {
			var currentQueueEtag;
			if (type == "disc") {
				currentQueueEtag = disc_etag;
			} else if (type == "instant") {
				currentQueueEtag = instant_etag;
			}
			var data = {
				title_ref : movieID, 
				position : position, 
				etag : currentQueueEtag
			};
			postData("http://api.netflix.com/users/" + userID + "/queues/" + type, data, type, loading_id);
		}

		function remove_from_queue(movieID, queue) {
			var currentQueue;
			if (queue == "disc") {
				currentQueue = disc_etag;
			} else if (queue == "instant") {
				currentQueue = instant_etag;
			}

			var data = {
				etag : currentQueue
			};
			url = movieID;
			
			var params = {};
			params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.DOM;
			params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.OAUTH;
			params[gadgets.io.RequestParameters.OAUTH_SERVICE_NAME] = "netflix";
			params[gadgets.io.RequestParameters.OAUTH_USE_TOKEN] = "always";
			params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.DELETE;
			params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(data);
			gadgets.io.makeRequest(url, function (response) {
				if (response.oauthApprovalUrl) {
					var popup = shindig.oauth.popup({
						destination: response.oauthApprovalUrl + "&application_name=iGoogle+Netflix",
						windowOptions: null,
						onOpen: null,
						onClose: function() { fetchData(url, type, loading_id, queue); }
					});
					
					var personalize = document.getElementById('personalize');
					personalize.onclick = popup.createOpenerOnClick();
					var approvaldone = document.getElementById('approvaldone');
					approvaldone.onclick = popup.createApprovedOnClick();
				} else if (response.data) {
					updateEtag(response.data, queue);
					updateQueueSelected();
				} else {
					// The response.oauthError and response.oauthErrorText values may help debug
					// problems with your gadget.
					alert("OAuth error: " + response.oauthError + ": " + response.oauthErrorText);
				}
			}, params);
		}

		function updatePosition(movie_id, row_id, queue_number, queue) {
			if (document.getElementById(row_id).className == "") {
				current_selection = movie_id;
				document.getElementById(row_id).className = "queue_highlight";
				for (var i = 1; i < movies_in_queue; i++) {
					if (i != queue_number) {
						document.getElementById(queue + "_queue_" + i + "_position_link").className = "hide";
						document.getElementById(queue + "_queue_" + i + "_update_position_link").className = "";
					}
				}
			} else {
				current_selection = null;
				document.getElementById(row_id).className = "";
				for (var i = 1; i < movies_in_queue; i++) {
					if (i != queue_number) {
						document.getElementById(queue + "_queue_" + i + "_position_link").className = "";
						document.getElementById(queue + "_queue_" + i + "_update_position_link").className = "hide";
					}
				}
			}
		}

		function moveToPosition(row_id, new_position, queue) {
			if (current_selection != null) {
				document.getElementById(row_id).className = "";
				updateQueue(current_selection, new_position, queue);
				current_selection = null;
				for (var i = 1; i < movies_in_queue; i++) {
					document.getElementById(queue + "_queue_" + i + "_position_link").className = "";
					document.getElementById(queue + "_queue_" + i + "_update_position_link").className = "hide";
				}
				updateQueueSelected();
			}
		}

		var movies_in_queue = null;
		function showQueue(response, queue, loading_id) {
			clearArea("q_results");
			
			movies_in_queue = 1;
			var queueTable = document.createElement("table");
			queueTable.setAttribute("width", "250px");
			queueTable.setAttribute("cellspacing", "0");
			queueTable.setAttribute("cellpadding", "1");
			var headerRow = document.createElement("tr");
			headerRow.className = "table_header";
			
			var updatePositionColumn = document.createElement("td");
			//updatePositionColumn.appendChild(document.createTextNode("Update"));
			var queueColumn = document.createElement("td");
			queueColumn.appendChild(document.createTextNode("Order"));
			var topColumn = document.createElement("td");
			//topColumn.appendChild(document.createTextNode("Top"));
			var titleColumn = document.createElement("td");
			titleColumn.appendChild(document.createTextNode("Movie Title"));
			var removeColumn = document.createElement("td");
			//removeColumn.appendChild(document.createTextNode("Remove"));
			
			headerRow.appendChild(updatePositionColumn);
			headerRow.appendChild(queueColumn);
			headerRow.appendChild(topColumn);
			headerRow.appendChild(titleColumn);
			headerRow.appendChild(removeColumn);
			queueTable.appendChild(headerRow);
			
			var results_area = document.getElementById("q_results");
			var itemList = response.getElementsByTagName("queue").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "etag") {
						if (queue == "disc") {
							disc_etag = itemList.item(i).firstChild.nodeValue;
						} else if (queue == "instant") {
							instant_etag = itemList.item(i).firstChild.nodeValue;
						}
					}
					if (itemList.item(i).nodeName == "queue_item") {
						var nodeList = itemList.item(i).childNodes;
						for (var j = 0; j < nodeList.length ; j++) {
							var node = nodeList.item(j);
							if (node.nodeName != "#text") {
								if (node.nodeName == "id") {
									var movie_id = node.firstChild.nodeValue;
								}
								if (node.nodeName == "title") {
									var name = node.attributes.item("regular").value;
								}
								if (node.nodeName == "link" && node.attributes.item(1).value == "http://schemas.netflix.com/catalog/title") {
									var movie_link_id = node.attributes.item(0).value;
								}
								if (node.nodeName == "category" && node.attributes.item(0).value == "http://api.netflix.com/categories/queue_availability") {
									var movie_availability = node.attributes.item(2).value;
								}						
							}
						}
						var resultRow = document.createElement("tr");
						resultRow.setAttribute("id", queue + "_queue_" + movies_in_queue);
						if (movie_availability == "saved") {
							resultRow.className = "queue_saved";
						} else if (movie_availability == "awaiting release") {
							resultRow.className = "queue_awaiting_release";
						}
						
						var queuePosition = document.createElement("td");
						if (movie_availability == "available now") {
							queuePosition.setAttribute("id", queue + "_queue_" + movies_in_queue + "_position");
							var queuePositionLink = document.createElement("a");
							queuePositionLink.setAttribute("id", queue + "_queue_" + movies_in_queue + "_position_link");
							queuePositionLink.setAttribute("style", "cursor:pointer;cursor:hand;");
							queuePositionLink.setAttribute("onClick", "updatePosition('" + movie_id + "', '" + queue + "_queue_" + movies_in_queue + "', " + movies_in_queue + ", '" + queue + "');");
							var upDownArrow = document.createElement("div");
							upDownArrow.innerHTML = "&#8597;";
							queuePositionLink.appendChild(upDownArrow);
							queuePosition.appendChild(queuePositionLink);
						
							var updateQueuePositionLink = document.createElement("a");
							updateQueuePositionLink.className = "hide";
							updateQueuePositionLink.setAttribute("id", queue + "_queue_" + movies_in_queue + "_update_position_link");
							updateQueuePositionLink.setAttribute("style", "cursor:pointer;cursor:hand;");
							updateQueuePositionLink.setAttribute("onClick", "moveToPosition('" + queue + "_queue_" + movies_in_queue + "', " + movies_in_queue + ", '" + queue + "');updateQueueSelected();");
							var rightArrow = document.createElement("div");
							rightArrow.innerHTML = "&#8658; ";
							updateQueuePositionLink.appendChild(rightArrow);
							queuePosition.appendChild(updateQueuePositionLink);
						}
						
						var queueNumber = document.createElement("td");
						queueNumber.setAttribute("align", "center");
						queueNumber.appendChild(document.createTextNode(movies_in_queue));
						
						var moveToTop = document.createElement("td");
						if (movie_availability == "available now") {
							moveToTop.setAttribute("align", "center");
							var moveToTopLink = document.createElement("a");
							moveToTopLink.setAttribute("style", "cursor:pointer;cursor:hand;");
							moveToTopLink.setAttribute("onClick", "updateQueue('" + movie_id + "', 1, '" + queue + "');updateQueueSelected();");
							var upArrow = document.createElement("div");
							upArrow.innerHTML = "&#8679;";
							moveToTopLink.appendChild(upArrow);
							moveToTop.appendChild(moveToTopLink);
						}
						
						var movieTitle = document.createElement("td");
						var movie_link = document.createElement("a");
						movie_link.setAttribute("style", "cursor:pointer;cursor:hand;");
						movie_link.setAttribute("onClick", "fetchData('http://api.netflix.com/users/" + userID + "/ratings/title?title_refs=" + percentEncode(movie_id) + "&expand=cast,directors,formats,similars,synopsis', 'movie_details', '" + loading_main_div + "');");
						movie_link.appendChild(document.createTextNode(name));
						movieTitle.appendChild(movie_link);
						
						var removeFromQueue = document.createElement("td");	
						removeFromQueue.setAttribute("align", "center");
						var link = document.createElement("a");
						link.setAttribute("style", "cursor:pointer;cursor:hand;");
						link.setAttribute("onClick", "remove_from_queue('" + movie_id + "','" + queue + "');");
						link.appendChild(document.createTextNode("x"));
						removeFromQueue.appendChild(link);
						
						resultRow.appendChild(queuePosition);
						resultRow.appendChild(queueNumber);
						resultRow.appendChild(moveToTop);
						resultRow.appendChild(movieTitle);
						resultRow.appendChild(removeFromQueue);
						queueTable.appendChild(resultRow);
											
						movies_in_queue++;
					}
				}
			}
			results_area.appendChild(queueTable);
			document.getElementById(loading_id).className = "queue_loading_div_back";
		}
		/* -------------------------------------------------------------- */
		/* -------------------- Initialization -------------------------- */
		/* -------------------------------------------------------------- */
		function init() {		
			linkHistory = new Array();		
			getUserID();
		}
		
		/* -------------------------------------------------------------- */
		/* -------------------- Home Screen -------------------------- */
		/* -------------------------------------------------------------- */
		function getHomeScreen(fromBackLink) {
			clearArea("result_output");
			if (!fromBackLink) {
				if (currentPage != null) {
					linkHistory[linkHistoryLength] = currentPage;
					linkHistoryLength++;
				}
				currentPage = "home";
			}
			fetchData("http://api.netflix.com/users/" + userID + "/at_home?max_results=5", "at_home");
			fetchData("http://api.netflix.com/users/" + userID + "/rental_history/returned?max_results=5", "returned");
		}
		
		function showAtHomeFeed(response) {
			var results_area = document.getElementById("result_output");
			var atHomeDiv = document.createElement("div");
			results_area.appendChild(atHomeDiv);
			var atHomeHeader = document.createElement("div");
			atHomeDiv.appendChild(atHomeHeader);
			atHomeHeader.className = "sectionHeader";
			atHomeHeader.appendChild(document.createTextNode("At Home:"));
			
			var atHomeList = document.createElement("ul");
			atHomeDiv.appendChild(atHomeList);
			atHomeList.setAttribute("type", "disc");
			var itemList = response.getElementsByTagName("at_home").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {	
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "at_home_item") {
						var name = "";
						var movie_id = "";
						var nodeList = itemList.item(i).childNodes;
						for (var j = 0; j < nodeList.length ; j++) {
							var node = nodeList.item(j);
							if (node.nodeName != "#text") {
								if (node.nodeName == "link" && node.attributes.item(1).value == "http://schemas.netflix.com/catalog/title") {
									movie_id = node.attributes.item(0).value;
								}
								if (node.nodeName == "title") {
									name = node.attributes.item("regular").value;
								}
							}
						}
						var movieItem = document.createElement("li");
						var movie_link = document.createElement("a");
						movie_link.setAttribute("style", "cursor:pointer;cursor:hand;");
						movie_link.setAttribute("onClick", "fetchData('http://api.netflix.com/users/" + userID + "/ratings/title?title_refs=" + percentEncode(movie_id) + "&expand=cast,directors,formats,similars,synopsis', 'movie_details', '" + loading_main_div + "');");
						movie_link.appendChild(document.createTextNode(name));
						movieItem.appendChild(movie_link);
						atHomeList.appendChild(movieItem);
					}
				}
			}
			document.getElementById(loading_main_div).className = "main_loading_div_back";
		}
		
		function showReturned(response) {
			var results_area = document.getElementById("result_output");
			var returnedDiv = document.createElement("div");
			results_area.appendChild(returnedDiv);
			var returnedHeader = document.createElement("div");
			returnedDiv.appendChild(returnedHeader);
			returnedHeader.className = "sectionHeader";
			returnedHeader.appendChild(document.createTextNode("Returned:"));
			
			var returnedList = document.createElement("ul");
			returnedDiv.appendChild(returnedList);
			returnedList.setAttribute("type", "disc");
			var itemList = response.getElementsByTagName("rental_history").item(0).childNodes;
			for (var i = 0; i < itemList.length ; i++) {	
				if (itemList.item(i).nodeName != "#text") {
					if (itemList.item(i).nodeName == "rental_history_item") {
						var name = "";
						var movie_id = "";
						var nodeList = itemList.item(i).childNodes;
						for (var j = 0; j < nodeList.length ; j++) {
							var node = nodeList.item(j);
							if (node.nodeName != "#text") {
								if (node.nodeName == "link" && node.attributes.item(1).value == "http://schemas.netflix.com/catalog/title") {
									movie_id = node.attributes.item(0).value;
								}
								if (node.nodeName == "title") {
									name = node.attributes.item("regular").value;
								}
							}
						}
						var movieItem = document.createElement("li");
						var movie_link = document.createElement("a");
						movie_link.setAttribute("style", "cursor:pointer;cursor:hand;");
						movie_link.setAttribute("onClick", "fetchData('http://api.netflix.com/users/" + userID + "/ratings/title?title_refs=" + percentEncode(movie_id) + "&expand=cast,directors,formats,similars,synopsis', 'movie_details', '" + loading_main_div + "');");
						movie_link.appendChild(document.createTextNode(name));
						movieItem.appendChild(movie_link);
						returnedList.appendChild(movieItem);
					}
				}
			}
			document.getElementById(loading_main_div).className = "main_loading_div_back";
		}